package com.amikomgamedev.labirinhantu.grafik;

import org.andengine.engine.camera.ZoomCamera;
import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.sprite.TiledSprite;
import org.andengine.extension.tmx.TMXObject;
import org.andengine.extension.tmx.TMXObjectGroup;
import org.andengine.util.color.Color;

import android.content.Context;

import com.amikomgamedev.labirinhantu.Memory_DB;
import com.amikomgamedev.labirinhantu.Rule;
import com.amikomgamedev.labirinhantu.Server_Data;
import com.amikomgamedev.labirinhantu.Utils;
import com.amikomgamedev.labirinhantu.game.Game_Config;

public class Grafik_Attach 	extends Grafik_Load
							implements Grafik_Anim
							, Rule
{
	
	int i = 0;
	
	public Grafik_Attach(Context context
			, Scene p_Scene
			, HUD p_Hud
			, ZoomCamera p_Camera)
	{
		super(context, p_Scene, p_Hud, p_Camera);
	}

	public void attachLogo(int index)
	{
		if (spr_Logo[index] == null)
		spr_Logo[index] = new Sprite(0, 0
					, Utils.getRatio(LOGO_WIDTH[index])
					, Utils.getRatio(LOGO_HEIGHT[index])
					, reg_Logo[index]
					, getVertex());
		
		spr_Logo[index].setPosition(
				(RES_WIDTH - spr_Logo[index].getWidth()) / 2
				, (RES_HEIGHT - spr_Logo[index].getHeight()) / 2);
		
		if (!spr_Logo[index].hasParent())
		    m_Scene.attachChild(spr_Logo[index]);
	}

	public void attachIconSocial()
	{
	    	float p_X[]	= 
	    		{
            			Utils.getRatio(10), 
            			Utils.getRatio(10) * 2 + Utils.getRatio(ICON_SOCIAL_WIDTH)
	    		};
	    
	    	for (int j = 0; j < ICON_SOCIAL.length; j++)
		{
        		spr_Icon_Social[j] = new Sprite(p_X[j]
        					, RES_HEIGHT - Utils.getRatio(15) - Utils.getRatio(ICON_SOCIAL_HEIGHT)
        					, Utils.getRatio(ICON_SOCIAL_WIDTH)
        					, Utils.getRatio(ICON_SOCIAL_HEIGHT)
        					, reg_Icon_Social[j]
        					, getVertex());

			m_Scene.registerTouchArea(spr_Icon_Social[j]);
        		spr_Menu_Main_Bg.attachChild(spr_Icon_Social[j]);
		}
	}
	
	public void attachIconSocialGame()
	{
	spr_Icon_Social_Game = new Sprite(
		(RES_WIDTH - Utils.getRatio(ICON_SOCIAL_WIDTH)) / 2,
		RES_HEIGHT - Utils.getRatio(10) - Utils
			.getRatio(ICON_SOCIAL_HEIGHT),
		Utils.getRatio(ICON_SOCIAL_WIDTH),
		Utils.getRatio(ICON_SOCIAL_HEIGHT),
		reg_Icon_Social[0],
		getVertex());

	m_Hud.registerTouchArea(spr_Icon_Social_Game);
	lst_Game_Over_Bg.get(0).attachChild(spr_Icon_Social_Game);
	}
	
	public void attachLoading()
	{
		if (spr_Menu_Loading == null)
			spr_Menu_Loading = new Sprite(0, 0
					, RES_WIDTH
					, RES_HEIGHT
					, reg_Menu_Loading
					, getVertex());	
		
		m_Scene.attachChild(spr_Menu_Loading);
	}
	
	public void attachMenuMainBg()
	{
		if (spr_Menu_Main_Bg == null)
			spr_Menu_Main_Bg = new Sprite(0, 0
					, RES_WIDTH
					, RES_HEIGHT
					, reg_Menu_Main_Bg
					, getVertex());
		
		m_Scene.attachChild(spr_Menu_Main_Bg);
		
		// attach logo hantu di main menu
		if(spr_LogoHantu == null)
		{
			spr_LogoHantu = new Sprite(0, 0
					, Utils.getRatio(LOGO_HANTU_WIDTH)
					, Utils.getRatio(LOGO_HANTU_HEIGHT)
					, reg_LogoHantu
					, getVertex());
		}
		
		spr_LogoHantu.setPosition(
				Utils.getRatioW(460), 
				Utils.getRatioH(5));
		
		spr_Menu_Main_Bg.attachChild(spr_LogoHantu);
		
		// attach lonceng di main menu
		if(asp_Menu_Lonceng == null){
			asp_Menu_Lonceng = new AnimatedSprite(
					Utils.getRatioW(160), 
					Utils.getRatioH(140),
					Utils.getRatioW(MENU_LONCENG_WIDTH),
					Utils.getRatioH(MENU_LONCENG_HEIGHT),
					reg_Menu_Lonceng,
					getVertex());
		}
		spr_Menu_Main_Bg.attachChild(asp_Menu_Lonceng);
		asp_Menu_Lonceng.animate(MENU_LONCENG_DUR);
		
		// attach kelelawar
		if(spr_Menu_Kelelawar == null)
		{
			spr_Menu_Kelelawar = new AnimatedSprite(
					0, 0,
					Utils.getRatioW(MENU_KELELAWAR_WIDTH),
					Utils.getRatioH(MENU_KELELAWAR_HEIGHt), 
					reg_Menu_Kelelawar, 
					getVertex());
		}
		
		spr_Menu_Kelelawar.setPosition(Utils.getRatioW(345), Utils.getRatioH(40));
		
		spr_Menu_Main_Bg.attachChild(spr_Menu_Kelelawar);
		spr_Menu_Kelelawar.animate(MENU_KELELAWAR_DUR);
		
	}
	
	public void attachMenuMainBtn()
	{
		is_Menu_Main_Active = false;
		
		for (int i = 0; i < MENU_MAIN_BTN.length; i++)
		{
			spr_Menu_Main_Btn[i] = new Sprite(0, 0
					, Utils.getRatio(MENU_MAIN_BTN_WIDTH)
					, Utils.getRatio(MENU_MAIN_BTN_HEIGHT)
					, reg_Menu_Main_Btn[i]
					, getVertex());
			
		}
		
		// set posisi button play
		spr_Menu_Main_Btn[0].setPosition(Utils.getRatioW(470), Utils.getRatioH(350));
		// set posisi button credit 
		spr_Menu_Main_Btn[1].setPosition(Utils.getRatioW(600), Utils.getRatioH(365));
		// set posisi button help
		spr_Menu_Main_Btn[2].setPosition(Utils.getRatioW(330), Utils.getRatioH(370));
		
		for(int i=0; i < MENU_MAIN_BTN.length; i++)
		{
			//m_Scene.registerTouchArea(spr_Menu_Main_Btn[i]);
			spr_Menu_Main_Bg.attachChild(spr_Menu_Main_Btn[i]);
			m_Scene.registerTouchArea(spr_Menu_Main_Btn[i]);
		}
		
	}
	
//	public void attachBtnMenuSelectStage()
//	{
//		for(int i=0; i<2; i++)
//		{
//			spr_Btn_Menu_Select_Stage[i] = new Sprite(
//					0, 0, 
//					Utils.getRatio(MENU_LEVEL_BTN_WIDTH), 
//					Utils.getRatio(MENU_LEVEL_BTN_HEIGHT), 
//					reg_Menu_Level_Btn[0], 
//					getVertex());
//			m_Hud.attachChild(spr_Btn_Menu_Select_Stage[i]);
//			m_Hud.registerTouchArea(spr_Btn_Menu_Select_Stage[i]);
//		}
//		
//		spr_Btn_Menu_Select_Stage[0].setPosition(0, (RES_HEIGHT/2) - (reg_Menu_Level_Btn[0].getWidth()/2));
//		
//		spr_Btn_Menu_Select_Stage[1].setPosition(RES_WIDTH - reg_Menu_Level_Btn[0].getWidth(), (RES_HEIGHT/2) - (reg_Menu_Level_Btn[0].getWidth()/2));
//		spr_Btn_Menu_Select_Stage[1].setFlippedHorizontal(true);
//	}
	
	public void attachMenuSelectStage()
	{
		for(int i=0; i<MENU_SELECT_STAGE_BG.length;i++)
		{
			spr_Menu_Select_Stage[i] = new Sprite(
					0, 0,
					RES_WIDTH, 
					RES_HEIGHT, 
					reg_Menu_Select_Stage[i], 
					getVertex());
			
			m_Scene.attachChild(spr_Menu_Select_Stage[i]);
		}		
		setPosMenuSelectStage();
		
		
	}
	
	public void attachMenuStageLingkaran()
	{
		float[] p_X	= 
		    {
			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2 - MENU_SELECT_LINGKARAN_WIDTH * 2,
			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2,
			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2 + MENU_SELECT_LINGKARAN_WIDTH * 2
		    };
		
		for (int i = 0; i < spr_Menu_Select_Stage.length; i++)
		{
		    spr_Menu_Lingkaran = new TiledSprite(0, 0
				, Utils.getRatio(MENU_SELECT_LINGKARAN_WIDTH)
				, Utils.getRatio(MENU_SELECT_LINGKARAN_HEIGHT)
				, reg_Menu_Lingkaran
				, getVertex());
		    
		    spr_Menu_Lingkaran.setPosition(
			    RES_WIDTH + p_X[i],
			    RES_HEIGHT - spr_Menu_Lingkaran.getHeight());
		    m_Scene.attachChild(spr_Menu_Lingkaran);
		    lst_Menu_Stage_Lingkaran.add(spr_Menu_Lingkaran);
		}
	}
	
	public void attachMenuLevelLingkaran()
	{
		float[][] p_X	= 
		    {
			{
			    (RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2,
			},			
			{
            			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2 - MENU_SELECT_LINGKARAN_WIDTH,
            			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2 + MENU_SELECT_LINGKARAN_WIDTH
			}
		    };
		
		int max	= MAP[Server_Data.getStage()].length / 10;
		
		for (int i = 0; i < rec_Menu_Level_Bg.length; i++)
		{
		    if (i < max)
		    {
        		    spr_Menu_Lingkaran = new TiledSprite(0, 0
        				, Utils.getRatio(MENU_SELECT_LINGKARAN_WIDTH)
        				, Utils.getRatio(MENU_SELECT_LINGKARAN_HEIGHT)
        				, reg_Menu_Lingkaran
        				, getVertex());
        		    
        		    spr_Menu_Lingkaran.setPosition(
        			    p_X[max - 1][i],
        			    RES_HEIGHT - spr_Menu_Lingkaran.getHeight());
        		    m_Scene.attachChild(spr_Menu_Lingkaran);
        		    lst_Menu_Level_Lingkaran.add(spr_Menu_Lingkaran);
		    }
		}
	}
	
	public void attachMenuHelpLingkaran()
	{
		float[] p_X	= 
		    {
    			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2 - MENU_SELECT_LINGKARAN_WIDTH,
    			(RES_WIDTH - MENU_SELECT_LINGKARAN_WIDTH) / 2 + MENU_SELECT_LINGKARAN_WIDTH
		    };
		
		for (int i = 0; i < spr_Menu_Help.length; i++)
		{
		    spr_Menu_Lingkaran = new TiledSprite(0, 0
				, Utils.getRatio(MENU_SELECT_LINGKARAN_WIDTH)
				, Utils.getRatio(MENU_SELECT_LINGKARAN_HEIGHT)
				, reg_Menu_Lingkaran
				, getVertex());
		    
		    spr_Menu_Lingkaran.setPosition(
			    - RES_WIDTH + p_X[i],
			    RES_HEIGHT - spr_Menu_Lingkaran.getHeight());
		    m_Scene.attachChild(spr_Menu_Lingkaran);
		    lst_Menu_Help_Lingkaran.add(spr_Menu_Lingkaran);
		}
	}
	
	public void setPosMenuSelectStage()
	{
		spr_Menu_Select_Stage[0].setPosition(RES_WIDTH, 0);
		spr_Menu_Select_Stage[1].setPosition(RES_WIDTH + spr_Menu_Select_Stage[0].getWidth(), 0);
		spr_Menu_Select_Stage[2].setPosition(RES_WIDTH + spr_Menu_Select_Stage[0].getWidth() + spr_Menu_Select_Stage[1].getWidth(), 0);
	}
	
	public void attachMenuLevelBg(int x)
	{
//		if (spr_Menu_Level_Bg == null)
			spr_Menu_Level_Bg = new Sprite(0, 0
					, RES_WIDTH
					, RES_HEIGHT
					, reg_Menu_Level_Bg[x]
					, getVertex());

		m_Scene.attachChild(spr_Menu_Level_Bg);
		
		for (int i = 0; i < rec_Menu_Level_Bg.length; i++)
		{
		    if (i < MAP[Server_Data.getStage()].length / 10)
		    {
			rec_Menu_Level_Bg[i] = new Rectangle(0, 0, 
				RES_WIDTH, RES_HEIGHT,
				getVertex());
			rec_Menu_Level_Bg[i].setColor(Color.TRANSPARENT);
//			rec_Menu_Level_Bg[i].setVisible(false);
			
			spr_Menu_Level_Bg.attachChild(rec_Menu_Level_Bg[i]);
		    }
		}
		
		if (Server_Data.getMap() < 10)
		{
		    if ((int) MAP[Server_Data.getStage()].length / 10 == 1)
			rec_Menu_Level_Bg[0].setPosition(0, 0);
		    if ((int) MAP[Server_Data.getStage()].length / 10 == 2)
		    {
			rec_Menu_Level_Bg[0].setPosition(0, 0);
			rec_Menu_Level_Bg[1].setPosition(RES_WIDTH, 0);	
		    }
		}
		else
		{
		    rec_Menu_Level_Bg[0].setPosition(-RES_WIDTH, 0);
		    rec_Menu_Level_Bg[1].setPosition(0, 0);
		}
		
		
	}
	
	public void attachMenuLevelBtn()
	{
//	    if (spr_Menu_Level_Btn[0][0] == null)
//		spr_Menu_Level_Btn[0][0] = new Sprite(0, 0
//			, Utils.getRatioW(MENU_LEVEL_BTN_WIDTH)
//			, Utils.getRatio(MENU_LEVEL_BTN_HEIGHT)
//			, reg_Menu_Level_Btn[0]
//			, getVertex());
	    
	    
		for (int i = 0; i < MAP[Server_Data.getStage()].length; i++)
		{
			spr_Menu_Level_Btn[i] = new Sprite(0, 0
				, Utils.getRatioW(MENU_LEVEL_BTN_WIDTH)
				, Utils.getRatio(MENU_LEVEL_BTN_HEIGHT)
				, reg_Menu_Level_Btn
				, getVertex());
			
			m_Scene.registerTouchArea(spr_Menu_Level_Btn[i]);
		}
		
//		float posX = (RES_WIDTH - spr_Menu_Level_Btn[0][0].getWidth() * 4) / 5;
//		float posY = (RES_HEIGHT - spr_Menu_Level_Btn[0][0].getHeight() * 3) / 4;
		
//		spr_Menu_Level_Btn[0][0].setPosition(posX, RES_HEIGHT - spr_Menu_Level_Btn[0][0].getHeight() - posY);

//		spr_Menu_Level_Bg.attachChild(spr_Menu_Level_Btn[0][0]);
		
		float posX = (RES_WIDTH - spr_Menu_Level_Btn[0].getWidth() * 4) / 5;
		float posY = (RES_HEIGHT - spr_Menu_Level_Btn[0].getHeight() * 3) / 4;
		
		float x = - spr_Menu_Level_Btn[0].getWidth();

		for (int i = 0; i < MAP[Server_Data.getStage()].length; i++)
		{
		    if (i < 4 || (i >= 10 && i < 14))
		    {
			x = x + posX + spr_Menu_Level_Btn[i].getWidth();
			spr_Menu_Level_Btn[i].setPosition(x, posY);
		    }
		    else if (i < 8 || (i >= 14 && i < 18))
		    {
			if (i == 4 || i == 14)
			{
				x = - spr_Menu_Level_Btn[i].getWidth();
				posY = posY * 2 + spr_Menu_Level_Btn[i].getHeight();
			}
			x = x + posX + spr_Menu_Level_Btn[i].getWidth();
			spr_Menu_Level_Btn[i].setPosition(x, posY);
		    }
		    else
		    {
			if (i == 8 || i == 18)
			{
			    	posY = (RES_HEIGHT - spr_Menu_Level_Btn[0].getHeight() * 3) / 4;
				x = posX;
				posY = posY * 3 + spr_Menu_Level_Btn[i].getHeight() * 2;
			}
			x = x + posX + spr_Menu_Level_Btn[i].getWidth();
			spr_Menu_Level_Btn[i].setPosition(x, posY);
		    }
		    
		    if (i < 10)
			rec_Menu_Level_Bg[0].attachChild(spr_Menu_Level_Btn[i]);
		    else
			rec_Menu_Level_Bg[1].attachChild(spr_Menu_Level_Btn[i]);
		    
		    if (i == 9)
		    {
			x = - spr_Menu_Level_Btn[0].getWidth();
			posY = (RES_HEIGHT - spr_Menu_Level_Btn[0].getHeight() * 3) / 4;
		    }
		}
	}
	
	public void attachMenuLevelGembok(Memory_DB m_DB)
	{
	    if (UNLOCK_ALL) return;
	    
	    for (int i = 0; i < MAP[Server_Data.getStage()].length; i++)
	    {
		if (m_DB.getTulang(Server_Data.getStage(), i) == 0
			&& i < MAP[Server_Data.getStage()].length - 1)
		{
			spr_Menu_Level_Btn_Gembok = new Sprite(
					0, 0, 
					Utils.getRatio(MENU_LEVEL_GEMBOK_WIDTH), 
					Utils.getRatio(MENU_LEVEL_GEMBOK_HEIGHT),
					reg_Menu_Level_Btn_Gembok, 
					getVertex());
		    spr_Menu_Level_Btn_Gembok.setPosition((
				spr_Menu_Level_Btn[i + 1].getWidth()/2) - (spr_Menu_Level_Btn_Gembok.getWidth()/2), 
				(spr_Menu_Level_Btn[i + 1].getHeight()/2) - (spr_Menu_Level_Btn_Gembok.getHeight()/2));
		    spr_Menu_Level_Btn[i + 1].attachChild(spr_Menu_Level_Btn_Gembok);
		    lst_Menu_Level_Btn_Gembok.add(spr_Menu_Level_Btn_Gembok);
		}
	    }
	}
	
	public void attachMenuLevelTulang(Memory_DB m_DB)
	{
	    for (int i = 0; i < MAP[Server_Data.getStage()].length; i++)
	    {
		if (m_DB.getTulang(Server_Data.getStage(), i) > 0)
		{
		    for (int j = 0; j < m_DB.getTulang(Server_Data.getStage(), i); j++)
		    {
				spr_Menu_Level_Btn_Tulang[i][j] = new Sprite(
            				0, 0, 
            				Utils.getRatio(MENU_LEVEL_TULANG_WIDTH), 
            				Utils.getRatio(MENU_LEVEL_TULANG_HEIGHT),
            				reg_Menu_Level_Btn_Tulang,
            				getVertex());
				
                    	    	float x = (spr_Menu_Level_Btn[i].getWidth() 
                    	    		- spr_Menu_Level_Btn_Tulang[i][j].getWidth() * (m_DB.getTulang(Server_Data.getStage(), i))) 
                    	    		/ (m_DB.getTulang(Server_Data.getStage(), i) + 1);
				
    				spr_Menu_Level_Btn_Tulang[i][j].setPosition(
    					spr_Menu_Level_Btn_Tulang[i][j].getWidth() * (j) + x * (j + 1),
    					(spr_Menu_Level_Btn[i].getHeight()/2) + ((spr_Menu_Level_Btn[i].getHeight()/2) - spr_Menu_Level_Btn_Tulang[i][j].getHeight())/2);
    				
                    	    spr_Menu_Level_Btn[i].attachChild(spr_Menu_Level_Btn_Tulang[i][j]);
		    }
			
		}
	    }
	}
	
	public void attachMenuCreditsBg()
	{
		if (spr_Menu_Credits_Bg == null)
			spr_Menu_Credits_Bg = new Sprite(0, RES_HEIGHT
					, RES_WIDTH
					, RES_HEIGHT
					, reg_Menu_Credits_Bg
					, getVertex());
		
		m_Scene.attachChild(spr_Menu_Credits_Bg);
		
		if(spr_Menu_Credits_Logo_Agd == null)
		{
			spr_Menu_Credits_Logo_Agd = new Sprite(
					0, 0, 
					Utils.getRatio(MENU_CREDITS_LOGOAGD_WIDTH),
					Utils.getRatio(MENU_CREDITS_LOGOAGD_HEIGHT),
					reg_Logo[0], 
					getVertex());
		}
		m_Hud.attachChild(spr_Menu_Credits_Logo_Agd);
		
		if(spr_Menu_Credits_Logo_Amikom == null)
		{
			spr_Menu_Credits_Logo_Amikom = new Sprite(
					0, 0, 
					Utils.getRatio(MENU_CREDITS_LOGOAMIKOM_WIDTH),
					Utils.getRatio(MENU_CREDITS_LOGOAMIKOM_HEIGHT),
					reg_Menu_Credits_Logo_Amikom, 
					getVertex());
		}
		
		m_Hud.attachChild(spr_Menu_Credits_Logo_Amikom);	
		
		if(spr_Menu_Credits_Logo_Hantu == null)
		{
			spr_Menu_Credits_Logo_Hantu = new Sprite(
					0, 0, 
					Utils.getRatio(MENU_CREDITS_LOGOHANTU_WIDTH), 
					Utils.getRatio(MENU_CREDITS_LOGOHANTU_HEIGHT), 
					reg_LogoHantu, 
					getVertex());
		}
		m_Hud.attachChild(spr_Menu_Credits_Logo_Hantu);
		
		
	}
	
//	public void attachMenuHelpBg()
//	{
//		if (spr_Menu_Help_Bg == null)
//			spr_Menu_Help_Bg = new Sprite(-RES_WIDTH, 0
//					, RES_WIDTH
//					, RES_HEIGHT
//					, reg_Menu_Help_Bg
//					, getVertex());
//		
//		// posisi di kiri main menu
////		spr_Menu_Help_Bg.setPosition(
////				spr_Menu_Main_Bg.getX() - spr_Menu_Help_Bg.getWidth(), 
////				0);
//		
//		
//		m_Scene.attachChild(spr_Menu_Help_Bg);
//		
//		if(spr_Menu_Help_Coin == null)
//			spr_Menu_Help_Coin = new TiledSprite(
//					0, 0, 
//					MENU_HELP_COIN_WIDTH, 
//					MENU_HELP_COIN_HEIGHT, 
//					reg_Menu_Help_Coin, 
//					getVertex());
//		
//		spr_Menu_Help_Coin.setPosition(Utils.getRatioW(100), Utils.getRatioH(80));
//		
//		spr_Menu_Help_Bg.attachChild(spr_Menu_Help_Coin);
//		
//		if(spr_Menu_Help_Pelampung == null)
//			spr_Menu_Help_Pelampung = new Sprite(
//					0, 0,
//					MENU_HELP_PELAMPUNG_WIDTH,
//					MENU_HELP_PELAMPUNG_HEIGHT, 
//					reg_Menu_Help_Pelampung, 
//					getVertex());
//		spr_Menu_Help_Pelampung.setPosition(Utils.getRatioW(240), Utils.getRatioH(145));
//		spr_Menu_Help_Bg.attachChild(spr_Menu_Help_Pelampung);
//		
//		if(spr_Menu_Help_Tombol == null)
//		{
//			spr_Menu_Help_Tombol = new Sprite(
//					0, 0,
//					MENU_HELP_TOMBOL_WIDTH, 
//					MENU_HELP_TOMBOL_HEIGHT, 
//					reg_Menu_Help_Tombol, 
//					getVertex());
//			spr_Menu_Help_Tombol.setPosition(Utils.getRatioW(270), Utils.getRatioH(220));
//			spr_Menu_Help_Bg.attachChild(spr_Menu_Help_Tombol);
//		}
//	}
	

	
	public void attachMenuHelp()
	{
		for(int i=0; i<spr_Menu_Help.length;i++)
		{
		    	spr_Menu_Help[i] = new Sprite(
					0, 0,
					RES_WIDTH, 
					RES_HEIGHT, 
					reg_Menu_Help[i], 
					getVertex());
			
			m_Scene.attachChild(spr_Menu_Help[i]);
			
			if (i == 0)
			    spr_Menu_Help[i].setPosition(- RES_WIDTH, 0);
			if (i == 1)
			    spr_Menu_Help[i].setPosition(- (RES_WIDTH * 2), 0);
		}
	}
	
	public void attachMenuMCbernafas()
	{
		if(spr_Menu_Mc_Bernafas == null)
		{
			spr_Menu_Mc_Bernafas = new AnimatedSprite(
					0,
					0,
					Utils.getRatio(MENU_MC_BERNAFAS_WIDTH), Utils.getRatio(MENU_MC_BERNAFAS_HEIGHT),
					reg_Menu_Mc_Bernafas,
					getVertex());
		}
		spr_Menu_Main_Bg.attachChild(spr_Menu_Mc_Bernafas);
		spr_Menu_Mc_Bernafas.setPosition(Utils.getRatioW(40), Utils.getRatioH(230));
		
		spr_Menu_Mc_Bernafas.animate(MENU_MC_BERNAFAS_DUR);
		
	}
	
	public void attachGamePlayBg()
	{
	    	rec_Game_Play_Bg	= new Rectangle(-500, -500,
	    		3000, 3000, getVertex());
	    	rec_Game_Play_Bg.setColor(Color.BLACK);
	    	m_Scene.attachChild(rec_Game_Play_Bg);
	    	
		tmx_Layer_Game_Play = tmx_Tiled_Game_Play.getTMXLayers().get(0);

		m_Scene.attachChild(tmx_Layer_Game_Play);
	}
	
	public void attachGamePlayMc(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{	for (int i = 0; i < 2; i++)
        	{
        		if (spr_Game_Play_Mc[i] == null)
        			spr_Game_Play_Mc[i] = new AnimatedSprite(0, 0
        					, GAME_PLAY_MC_WIDTH[i]
        					, GAME_PLAY_MC_HEIGHT[i]
        					, reg_Game_Play_Mc[i]
        					, getVertex());
        		spr_Game_Play_Mc[i].setPosition(p_X + 5, p_Y);
        		m_Scene.attachChild(spr_Game_Play_Mc[i]);        	    
        	}
	}
	
	public void attachGamePlayBtn()
	{		
		for (int i = 0; i < spr_Game_Play_Btn.length; i++)
		{
			if (spr_Game_Play_Btn[i] == null)
				spr_Game_Play_Btn[i] = new TiledSprite(0, 0
						, Utils.getRatio(GAME_PLAY_BTN_WIDTH[i])
						, Utils.getRatio(GAME_PLAY_BTN_HEIGHT[i])
						, reg_Game_Play_Btn[i]
						, getVertex());
			
			if (i == 0)
			{
				spr_Game_Play_Btn[i].setPosition(Utils.getRatio(20)
						, RES_HEIGHT - spr_Game_Play_Btn[i].getHeight() - Utils.getRatio(20));
				spr_Game_Play_Btn[i].setVisible(false);
			}
			else
			{
				m_Hud.registerTouchArea(spr_Game_Play_Btn[i]);
			
				spr_Game_Play_Btn[i].setPosition(RES_SPLIT_MAIN_WIDTH + (RES_SPLIT_TASKBAR_WIDTH - spr_Game_Play_Btn[i].getWidth()) / 2
						, Utils.getRatio(0));
			}
			
			    m_Hud.attachChild(spr_Game_Play_Btn[i]);
		}
	}
	
//	public void attachGamePlayControl()
//	{
//	    dig_Game_Play_Control	= new DigitalOnScreenControl(
//			0,
//			0,
//			m_Camera,
//			reg_Game_Play_Control_Base,
//			reg_Game_Play_Control_Knob,
//			0.1f,
//			activity.getVertexBufferObjectManager(),
//			m_Control);
//	    
//	    m_Scene.setChildScene(dig_Game_Play_Control);
//	}
	
	public void attachGamePlayRecNavigasi(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		rec_Game_Play_Btn = new Rectangle(Utils.getRatio(p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, getVertex());
		
		if (!Game_Config.DEBUG)
			rec_Game_Play_Btn.setVisible(false);

		m_Hud.registerTouchArea(rec_Game_Play_Btn);
		spr_Game_Play_Btn[0].attachChild(rec_Game_Play_Btn);
		lst_Game_Play_Btn.add(rec_Game_Play_Btn);
	}
	
	public void attachGamePlayFloat(float p_X, float p_Y)
	{
		spr_Game_Play_Float = new AnimatedSprite(
				p_X , p_Y
				, GAME_PLAY_FLOAT_WIDTH
				, GAME_PLAY_FLOAT_HEIGHT
				, reg_Game_Play_Float
				, getVertex());

		spr_Game_Play_Float.animate(GAME_PLAY_FLOAT_DUR);
		m_Scene.attachChild(spr_Game_Play_Float);
		
		lst_Game_Play_Float.add(spr_Game_Play_Float);
	}
	
	public void attachGamePlayGhost(float p_X, float p_Y)
	{
		spr_Game_Play_Ghost = new AnimatedSprite(
				p_X , p_Y 
//				, GAME_PLAY_GHOST_WIDTH
//				, GAME_PLAY_GHOST_HEIGHT
				, reg_Game_Play_Ghost[Server_Data.getStage()]
				, getVertex());
//		spr_Game_Play_Ghost.setVisible(false);
		
		m_Scene.attachChild(spr_Game_Play_Ghost);
		
		lst_Game_Play_Ghost.add(spr_Game_Play_Ghost);
	}
	
	public void attachGamePlayGhostInvisible(float p_X, float p_Y)
	{
		spr_Game_Play_Ghost = new AnimatedSprite(
				p_X , p_Y 
//				, GAME_PLAY_GHOST_WIDTH
//				, GAME_PLAY_GHOST_HEIGHT
				, reg_Game_Play_Ghost[Server_Data.getStage()]
				, getVertex());
		spr_Game_Play_Ghost.setVisible(false);
		
		m_Scene.attachChild(spr_Game_Play_Ghost);
		
		lst_Game_Play_Ghost_Invisible.add(spr_Game_Play_Ghost);
	}
	
	public void attachGamePlayCollection(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_Collection = new AnimatedSprite(
				p_X, p_Y
				, p_Width
				, p_Height
				, reg_Game_Play_Collection
				, getVertex());

		spr_Game_Play_Collection.animate(GAME_PLAY_COLLECTION_DUR);
		m_Scene.attachChild(spr_Game_Play_Collection);
		
		lst_Game_Play_Collection.add(spr_Game_Play_Collection);
	}
	
	public void attachGamePlayFire(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Play_Fire = new AnimatedSprite(
				p_X, p_Y
				, (p_Width > p_Height ? p_Width : p_Height) * 2
				, (p_Width < p_Height ? p_Width : p_Height) * 2
				, reg_Game_Play_Fire
				, getVertex());

		    if (p_Width > p_Height)
		    {
			spr_Game_Play_Fire.setRotation(0);
		    }
		    else
		    {
			spr_Game_Play_Fire.setRotationCenter(spr_Game_Play_Fire.getHeight() / 2,
				spr_Game_Play_Fire.getHeight() / 4);
			spr_Game_Play_Fire.setRotation(90);
		    }
			
		rec_Game_Play_Fire = new Rectangle(
			p_X, p_Y
			, p_Width
			, p_Height
			, getVertex());
		
		if (!Game_Config.DEBUG)
		    rec_Game_Play_Fire.setVisible(false);
		
		m_Scene.attachChild(rec_Game_Play_Fire);
		m_Scene.attachChild(spr_Game_Play_Fire);

		lst_rec_Game_Play_Fire.add(rec_Game_Play_Fire);
		lst_Game_Play_Fire.add(spr_Game_Play_Fire);
	}
	
	public void attachGamePlayMist(float p_X, float p_Y)
	{
		spr_Game_Play_Mist = new AnimatedSprite(
				p_X, p_Y
				, GAME_PLAY_MIST_WIDTH
				, GAME_PLAY_MIST_HEIGHT
				, reg_Game_Play_Mist
				, getVertex());

		spr_Game_Play_Mist.animate(GAME_PLAY_MIST_DUR);
		m_Scene.attachChild(spr_Game_Play_Mist);
		
		lst_Game_Play_Mist.add(spr_Game_Play_Mist);
	}
	
	public void attachGamePlayWall(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		rec_Game_Play_Wall = new Rectangle(p_X
				, p_Y
				, p_Width
				, p_Height
				, getVertex());
		
		if (!Game_Config.DEBUG)
			rec_Game_Play_Wall.setVisible(false);
		
		m_Scene.attachChild(rec_Game_Play_Wall);
		
		lst_Game_Play_Wall.add(rec_Game_Play_Wall);
	}
	
	public void attachGamePlayWater(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_Water = new AnimatedSprite(
				p_X, p_Y
				, p_Width
				, p_Height
				, reg_Game_Play_Water
				, getVertex());

		spr_Game_Play_Water.animate(GAME_PLAY_WATER_DUR);
		m_Scene.attachChild(spr_Game_Play_Water);
		
		lst_Game_Play_Water.add(spr_Game_Play_Water);
	}
	
	public void attachGamePlayBtnGhost(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_Btn_Ghost = new TiledSprite(p_X
				, p_Y
				, p_Width
				, p_Height
				, reg_Game_Play_Btn_Ghost
				, getVertex());
		
		tmx_Layer_Game_Play.attachChild(spr_Game_Play_Btn_Ghost);
		
		lst_Game_Play_Btn_Ghost.add(spr_Game_Play_Btn_Ghost);
	}
	
	public void attachGamePlayMoveGhost(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		rec_Game_Play_Move_Ghost = new Rectangle(p_X
				, p_Y
				, p_Width
				, p_Height
				, getVertex());
		
		if (!Game_Config.DEBUG)
			rec_Game_Play_Move_Ghost.setVisible(false);
		
		tmx_Layer_Game_Play.attachChild(rec_Game_Play_Move_Ghost);
		
		lst_Game_Play_Move_Ghost.add(rec_Game_Play_Move_Ghost);
	}
	
	public void attachGamePlayBtnMist(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
	    rec_Game_Play_Btn_Mist = new Rectangle(p_X
				, p_Y
				, p_Width
				, p_Height
				, getVertex());

		if (!Game_Config.DEBUG)
		    rec_Game_Play_Btn_Mist.setVisible(false);
		
		m_Scene.attachChild(rec_Game_Play_Btn_Mist);
		lst_Game_Play_Btn_Mist.add(rec_Game_Play_Btn_Mist);
	}
	
	public void attachGamePlayItemRight(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_Item_Right = new TiledSprite(p_X
				, p_Y
				, p_Width
				, p_Height
				, reg_Game_Play_Taskbar_Rule
				, getVertex());

		spr_Game_Play_Item_Right.setCurrentTileIndex(6);
		tmx_Layer_Game_Play.attachChild(spr_Game_Play_Item_Right);
		
		lst_Game_Play_Item_Right.add(spr_Game_Play_Item_Right);
	}
	
	public void attachGamePlayItemLeft(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_Item_Left = new TiledSprite(p_X
				, p_Y
				, p_Width
				, p_Height
				, reg_Game_Play_Taskbar_Rule
				, getVertex());
		spr_Game_Play_Item_Left.setCurrentTileIndex(4);
		tmx_Layer_Game_Play.attachChild(spr_Game_Play_Item_Left);
		
		lst_Game_Play_Item_Left.add(spr_Game_Play_Item_Left);
	}
	
	public void attachGamePlayFinish(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		rec_Game_Play_Finish = new Rectangle(p_X
				, p_Y
				, p_Width
				, p_Height
				, getVertex());
		
		if (!Game_Config.DEBUG)
			rec_Game_Play_Finish.setVisible(false);
		
		tmx_Layer_Game_Play.attachChild(rec_Game_Play_Finish);
		lst_Game_Play_Finish.add(rec_Game_Play_Finish);
	}
	
	public void attachObjectFromTMX()
	{
		for (TMXObjectGroup group : tmx_Tiled_Game_Play.getTMXObjectGroups())
		{
			if (group.getName().equals("start"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayMc(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("koin"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayCollection(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("pelampung"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayFloat(object.getX(), object.getY());

			if (group.getName().equals("hantu_b"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayGhost(object.getX(), object.getY());

			if (group.getName().equals("hantu_i"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayGhostInvisible(object.getX(), object.getY());

			
			if (group.getName().equals("api"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayFire(object.getX(), object.getY()
						, object.getWidth(), object.getHeight());

			if (group.getName().equals("kabut"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayMist(object.getX(), object.getY());

			if (group.getName().equals("pembatas"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayWall(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("air"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayWater(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("tb_hantu"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayBtnGhost(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("hantu_area"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayMoveGhost(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("tb_kabut"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayBtnMist(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("exit"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayFinish(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("R"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayItemRight(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());

			if (group.getName().equals("L"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayItemLeft(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
		}
	}
	
	public void attachObjInfoFrmTmx()
	{
		for (TMXObjectGroup group : tmx_Tiled_Informasi.getTMXObjectGroups())
		{
			if (group.getName().equals("rec_Navigasi"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayRecNavigasi(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("mc"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayTaskbarMc(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("btn_Zoom"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayTaskbarBtn(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("rule_" + RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()].length))
				for(TMXObject object : group.getTMXObjects())
					attachGamePlayTaskbarRule(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("pause_Bg"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePauseBg(object.getWidth(), object.getHeight());
			
			if (group.getName().equals("pause_Btn"))
				for(TMXObject object : group.getTMXObjects())
					attachGamePauseBtn(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("over_Bg"))
				for(TMXObject object : group.getTMXObjects())
					attachGameOverBg(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("over_Mc"))
				for(TMXObject object : group.getTMXObjects())
					attachGameOverMc(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("over_Btn"))
				for(TMXObject object : group.getTMXObjects())
					attachGameOverBtn(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("over_Txt"))
				for(TMXObject object : group.getTMXObjects())
					attachGameOverTxt(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
			
			if (group.getName().equals("over_darah"))
				for(TMXObject object : group.getTMXObjects())
					attachGameOverDarah(object.getX(), object.getY()
							, object.getWidth(), object.getHeight());
		}
	}
	
	public void attachObjGameWin()
	{
	    for (TMXObjectGroup group : tmx_Tiled_Game_Win.getTMXObjectGroups())
		{
		
		if (group.getName().equals("bg"))
			for(TMXObject object : group.getTMXObjects())
				attachGameWinBg(object.getX(), object.getY()
						, object.getWidth(), object.getHeight());
		
		if (group.getName().equals("mc"))
			for(TMXObject object : group.getTMXObjects())
				attachGameWinMc(object.getX(), object.getY()
						, object.getWidth(), object.getHeight());
		
		if (group.getName().equals("btn"))
			for(TMXObject object : group.getTMXObjects())
				attachGameWinBtn(object.getX(), object.getY()
						, object.getWidth(), object.getHeight());
		
		if (group.getName().equals("txt"))
			for(TMXObject object : group.getTMXObjects())
				attachGameWinTxt(object.getX(), object.getY()
						, object.getWidth(), object.getHeight());
		
		Utils.TRACE(" LEVEL + " +Server_Data.getStage());
		Utils.TRACE(" MAP + " +Server_Data.getMap());
		Utils.TRACE(" Tulang = " +Server_Data.getJmlTulang());
		
		if (group.getName().equals("tulang_" + Server_Data.getJmlTulang()))
			for(TMXObject object : group.getTMXObjects())
			    attachGameWinTulang(object.getX(), object.getY()
						, object.getWidth(), object.getHeight());
		
		}
	}
	
	public void attachGamePlayTaskbarBg()
	{
//		if (spr_Game_Play_Taskbar_Bg == null)
			spr_Game_Play_Taskbar_Bg = new Sprite(
					RES_SPLIT_MAIN_WIDTH
					, 0
					, RES_SPLIT_TASKBAR_WIDTH
					, RES_HEIGHT
					, reg_Game_Play_Taskbar_Bg
					, getVertex());
		
		m_Hud.attachChild(spr_Game_Play_Taskbar_Bg);
	}
	
	public void attachGamePlayTaskbarMc(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_TaskBar_Mc = new AnimatedSprite(
				Utils.getRatio(p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Play_TaskBar_Mc
				, getVertex());
		
		spr_Game_Play_TaskBar_Mc.animate(GAME_PLAY_TASKBAR_MC_DUR[1], GAME_PLAY_TASKBAR_MC_FRAME[1], true);
		spr_Game_Play_Taskbar_Bg.attachChild(spr_Game_Play_TaskBar_Mc);
	}
	
	public void attachGamePlayTaskbarBtn(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Play_TaskBar_Btn = new Sprite(
				Utils.getRatio(p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Play_TaskBar_Btn
				, getVertex());

		m_Hud.registerTouchArea(spr_Game_Play_TaskBar_Btn);
		spr_Game_Play_Taskbar_Bg.attachChild(spr_Game_Play_TaskBar_Btn);
	}
	
	public void attachGamePlayTaskbarRule(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		{
		    if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("KOIN"))
		    {
			spr_Game_Play_Koin = new TiledSprite(
				Utils.getRatio(p_X + 5)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(GAME_PLAY_TASKBAR_RULE_WIDTH[0])
				, Utils.getRatio(GAME_PLAY_TASKBAR_RULE_HEIGHT[0])
				, reg_Game_Play_Collection
				, getVertex());
			spr_Game_Play_Koin.setUserData("Koin");
			spr_Game_Play_Koin.setCurrentTileIndex(0);
			lst_Game_Play_Taskbar_Rule.add(spr_Game_Play_Koin);
			spr_Game_Play_Taskbar_Bg.attachChild(spr_Game_Play_Koin);
			Server_Data.setKoin(Integer.parseInt(RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].substring(5, 6)));
			
		    }
		    else
		    {
			
			if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("NO"))
    		    	{
				spr_Game_Play_Taskbar_Rule = new TiledSprite(
        					Utils.getRatio(p_X)
        					, Utils.getRatio(p_Y)
						, Utils.getRatio(GAME_PLAY_TASKBAR_RULE_WIDTH[1])
						, Utils.getRatio(GAME_PLAY_TASKBAR_RULE_HEIGHT[1])
						, reg_Game_Play_Taskbar_Rule
						, getVertex());
				
			    	if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("RIGHT"))
	    		    	{
	    		    	    Utils.TRACE("NO_RIGHT");
	    		    	    spr_Game_Play_Taskbar_Rule.setCurrentTileIndex(7);
	    		    	    Server_Data.setRight(0);
	    		    	}
	    		    	else if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("LEFT"))
	    		    	{
	    		    	    Utils.TRACE("NO_LEFT");
	    		    	    spr_Game_Play_Taskbar_Rule.setCurrentTileIndex(5);
	    		    	    Server_Data.setLeft(0);
	    		    	}
	    		    	else if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("BACK"))
	            		{
	            		    Utils.TRACE("NO_BACK");
	            		    spr_Game_Play_Taskbar_Rule.setCurrentTileIndex(1);
	    		    	    Server_Data.setBack(0);
	            		}
    		    	}
			else
			{
				spr_Game_Play_Taskbar_Rule = new TiledSprite(
        					Utils.getRatio(p_X + 5)
        					, Utils.getRatio(p_Y)
						, Utils.getRatio(GAME_PLAY_TASKBAR_RULE_WIDTH[0])
						, Utils.getRatio(GAME_PLAY_TASKBAR_RULE_HEIGHT[0])
						, reg_Game_Play_Taskbar_Rule
						, getVertex());
				
			    	if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("RIGHT"))
	    		    	{
	    		    	    Utils.TRACE("RIGHT");
	    		    	    spr_Game_Play_Taskbar_Rule.setUserData("Right");
	    		    	    spr_Game_Play_Taskbar_Rule.setCurrentTileIndex(6);
	    		    	    Server_Data.setRight(Integer.parseInt(RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].substring(5, 6)));
	    		    	}
	    		    	else if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("LEFT"))
	    		    	{
	    		    	    Utils.TRACE("LEFT");
	    		    	    spr_Game_Play_Taskbar_Rule.setUserData("Left");
	    		    	    spr_Game_Play_Taskbar_Rule.setCurrentTileIndex(4);
	    		    	    Server_Data.setLeft(Integer.parseInt(RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].substring(5, 6)));
	    		    	}
	    		    	else if (RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].contains("BACK"))
	            		{
	            		    Utils.TRACE("BACK");
	    		    	    spr_Game_Play_Taskbar_Rule.setUserData("Back");
	            		    spr_Game_Play_Taskbar_Rule.setCurrentTileIndex(0);
	            		    Server_Data.setBack(Integer.parseInt(RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()][i].substring(5, 6)));
	            		}
			}
			
			lst_Game_Play_Taskbar_Rule.add(spr_Game_Play_Taskbar_Rule);
			spr_Game_Play_Taskbar_Bg.attachChild(spr_Game_Play_Taskbar_Rule);
			
		    }
		    i++;
		    if (i == RULE_MOVE[Server_Data.getStage()][Server_Data.getMap()].length)
			i = 0;

		    float	height	= 0;
		    float	selisih	= 0;
		    
		    
		    for (int i = 0; i < lst_Game_Play_Taskbar_Rule.size(); i++)
		    {
			height += lst_Game_Play_Taskbar_Rule.get(i).getHeight();
		    }
		    
		    selisih = (Utils.getRatio(200) - height) / (lst_Game_Play_Taskbar_Rule.size() + 1);
		    
		    for (int i = 0; i < lst_Game_Play_Taskbar_Rule.size(); i++)
		    {
			if (i == 0)
			    lst_Game_Play_Taskbar_Rule.get(i).setPosition(
				    lst_Game_Play_Taskbar_Rule.get(i).getX(),
				    Utils.getRatio(200) + selisih);
			else
			    lst_Game_Play_Taskbar_Rule.get(i).setPosition(
				    lst_Game_Play_Taskbar_Rule.get(i).getX(),
				    lst_Game_Play_Taskbar_Rule.get(i - 1).getY() + lst_Game_Play_Taskbar_Rule.get(i - 1).getHeight() + Utils.getRatio(selisih));			    
		    }
		}
	}
	
	public void attachGamePauseBg(float p_Width
			, float p_Height)
	{
		if (spr_Game_Pause_Bg == null)
			spr_Game_Pause_Bg = new Sprite(0, 0
					, Utils.getRatioSplitMain(p_Width)
					, Utils.getRatioSplitMain(p_Height)
					, reg_Game_Pause_Bg
					, getVertex());
		
		spr_Game_Pause_Bg.setPosition((RES_SPLIT_MAIN_WIDTH - spr_Game_Pause_Bg.getWidth()) / 2
			, - spr_Game_Pause_Bg.getHeight());
//		, (RES_HEIGHT - spr_Game_Pause_Bg.getHeight()) / 2);
		
//		spr_Game_Pause_Bg.setVisible(false);
		m_Hud.attachChild(spr_Game_Pause_Bg);
	}
	
	public void attachGamePauseBtn(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		spr_Game_Pause_Btn = new TiledSprite(
				Utils.getRatioSplitMain(p_X)
				, Utils.getRatioSplitMain(p_Y)
				, Utils.getRatioSplitMain(p_Width)
				, Utils.getRatioSplitMain(p_Height)
				, reg_Game_Pause_Btn[i]
				, getVertex());
		i++;
		if (i == 3)
		    i = 0;
		m_Hud.registerTouchArea(spr_Game_Pause_Btn);
		lst_Game_Pause_Btn.add(spr_Game_Pause_Btn);
		spr_Game_Pause_Bg.attachChild(spr_Game_Pause_Btn);
	}
	
	public void attachGameOverBg(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		rec_Game_Over_Bg = new Rectangle(Utils.getRatioW(p_X)
				, Utils.getRatioH(p_Y)
				, Utils.getRatioW(p_Width)
				, Utils.getRatioH(p_Height)
				, getVertex());
		
		if (lst_Game_Over_Bg.size() == 1)
		{
		    rec_Game_Over_Bg.setColor(Color.WHITE);
		    lst_Game_Over_Bg.get(0).attachChild(rec_Game_Over_Bg);
//		    rec_Game_Over_Bg.registerEntityModifier(new ScaleModifier(0.25f, 1f, 1f, 0, 1f));
		}
		else
		{
		    rec_Game_Over_Bg.setVisible(false);
		    rec_Game_Over_Bg.setColor(Color.BLACK);
		    m_Hud.attachChild(rec_Game_Over_Bg);
		}
		lst_Game_Over_Bg.add(rec_Game_Over_Bg);
	}
	
	public void attachGameOverMc(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Over_MC = new Sprite(Utils.getRatio(p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Over_Mc
				, getVertex());

		lst_Game_Over_Bg.get(0).attachChild(spr_Game_Over_MC);
//		spr_Game_Over_MC.registerEntityModifier(new FadeInModifier(1f));
	}
	
	public void attachGameOverTxt(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Over_Txt = new Sprite(RES_WIDTH - Utils.getRatio(p_Width) - Utils.getRatioW(tmx_Tiled_Informasi.getTileWidth() * tmx_Tiled_Informasi.getTileColumns() - p_X - p_Width)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Over_Txt
				, getVertex());

		lst_Game_Over_Bg.get(0).attachChild(spr_Game_Over_Txt);
	}
	
	public void attachGameOverDarah(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Over_Darah = new AnimatedSprite(RES_WIDTH - Utils.getRatio(p_Width) - Utils.getRatioW(tmx_Tiled_Informasi.getTileWidth() * tmx_Tiled_Informasi.getTileColumns() - p_X - p_Width)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Over_Darah
				, getVertex());
		lst_Game_Over_Bg.get(0).attachChild(spr_Game_Over_Darah);
	}
	
	public void attachGameOverBtn(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Over_Btn = new TiledSprite(RES_WIDTH - Utils.getRatio(p_Width) - Utils.getRatioW(tmx_Tiled_Informasi.getTileWidth() * tmx_Tiled_Informasi.getTileColumns() - p_X - p_Width)
				, Utils.getRatioH(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Over_Btn[i]
				, getVertex());
		i++;
		if (i == 2)
		    i = 0;

		lst_Game_Over_Bg.get(0).attachChild(spr_Game_Over_Btn);
		lst_Game_Over_Btn.add(spr_Game_Over_Btn);
//		spr_Game_Over_Btn.registerEntityModifier(new FadeInModifier(2f));
		
//		m_Scene.registerUpdateHandler(new TimerHandler(2, new ITimerCallback()
//		{
//		    
//		    public void onTimePassed(TimerHandler pTimerHandler)
//		    {
			m_Hud.registerTouchArea(spr_Game_Over_Btn);
//		    }
//		}));
	}
	
	public void attachGameWinBg(float p_X
			, float p_Y
			, float p_Width
			, float p_Height)
	{
		rec_Game_Win_Bg = new Rectangle(Utils.getRatioW(p_X)
				, Utils.getRatioH(p_Y)
				, Utils.getRatioW(p_Width)
				, Utils.getRatioH(p_Height)
				, getVertex());
		
		if (lst_Game_Win_Bg.size() == 1)
		{
		    rec_Game_Win_Bg.setColor(Color.WHITE);
		    lst_Game_Win_Bg.get(0).attachChild(rec_Game_Win_Bg);
//		    rec_Game_Win_Bg.registerEntityModifier(new ScaleModifier(0.25f, 1f, 1f, 0, 1f));
		}
		else
		{
		    rec_Game_Win_Bg.setColor(Color.BLACK);
		    m_Hud.attachChild(rec_Game_Win_Bg);
		}
		lst_Game_Win_Bg.add(rec_Game_Win_Bg);
	}
	
	public void attachGameWinMc(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Win_Mc = new Sprite(Utils.getRatio(p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Win_Mc
				, getVertex());

		lst_Game_Win_Bg.get(0).attachChild(spr_Game_Win_Mc);
//		spr_Game_Win_Mc.registerEntityModifier(new FadeInModifier(1f));
	}
	
	public void attachGameWinTxt(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Win_Txt = new Sprite(RES_WIDTH - Utils.getRatioW(tmx_Tiled_Informasi.getTileWidth() * tmx_Tiled_Informasi.getTileColumns() - p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Win_Txt
				, getVertex());

		lst_Game_Win_Bg.get(0).attachChild(spr_Game_Win_Txt);
//		spr_Game_Win_Txt.registerEntityModifier(new FadeInModifier(1.5f));
	}
	
	public void attachGameWinBtn(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
	    if (Server_Data.getMap() != MAP[Server_Data.getStage()].length - 1
		    || i != 2)
	    {
		spr_Game_Win_Btn = new TiledSprite(RES_WIDTH - Utils.getRatioW(tmx_Tiled_Informasi.getTileWidth() * tmx_Tiled_Informasi.getTileColumns() - p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Win_Btn[i]
				, getVertex());
		i++;
		if (i == 3)
		    i = 0;

		m_Hud.registerTouchArea(spr_Game_Win_Btn);
		
		lst_Game_Win_Bg.get(0).attachChild(spr_Game_Win_Btn);
		lst_Game_Win_Btn.add(spr_Game_Win_Btn);
	    }
	    else
	    {
		for (int i = 0; i < 2; i++)
		{
		    lst_Game_Win_Btn.get(i).setPosition(lst_Game_Win_Btn.get(i).getX() +  Utils.getRatio(p_Width + 40) / 2,
			    lst_Game_Win_Btn.get(i).getY());
		}
		
		if (i == 2)
		    i = 0;
	    }
//		spr_Game_Win_Btn.registerEntityModifier(new FadeInModifier(2f));
	}
	
	public void attachGameWinTulang(float p_X
		, float p_Y
		, float p_Width
		, float p_Height)
	{
		spr_Game_Win_Tulang = new Sprite(RES_WIDTH - Utils.getRatioW(tmx_Tiled_Informasi.getTileWidth() * tmx_Tiled_Informasi.getTileColumns() - p_X)
				, Utils.getRatio(p_Y)
				, Utils.getRatio(p_Width)
				, Utils.getRatio(p_Height)
				, reg_Game_Win_Tulang
				, getVertex());

		lst_Game_Win_Bg.get(0).attachChild(spr_Game_Win_Tulang);
		lst_Game_Win_Tulang.add(spr_Game_Win_Tulang);
		spr_Game_Win_Tulang.setVisible(false);
	}
}
